import { useNavigate } from "react-router-dom";
import { useMemo } from "react";

export const useRouter = () => {
  const navigate = useNavigate();
  const router = useMemo(
    () => ({
      back: () => navigate(-1),
      go: (n: number) => navigate(n),
      push: (path: string) => navigate(path),
      reload: () => window.location.reload,
      replace: (path: string) => navigate(path, { replace: true }),
    }),
    [navigate],
  );
  return router;
};
